//
//  ZJShaiXuanVC.m
//  这家测试项目
//
//  Created by IOS_DEVELOPER on 2017/7/5.
//  Copyright © 2017年 陈志凌. All rights reserved.
//

#import "ZJShaiXuanVC.h"
#import "ZJShaixuanCell.h"

static NSString * house_layoutStr;
static NSString * areaStr;
static NSString * oriStr;

@interface ZJShaiXuanVC ()<UITableViewDelegate,UITableViewDataSource,ZJShaixuanCellDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;

@property (strong, nonatomic) UIWindow * window;
@end

@implementation ZJShaiXuanVC

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
     self.navigationController.navigationBarHidden = YES;
    house_layoutStr = nil;
    areaStr = nil;
    oriStr = nil;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.sureBtn setBackgroundColor:[Utils colorWithHexString:allConstHexColor]];
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableview registerNib:[UINib nibWithNibName:NSStringFromClass([ZJShaixuanCell class]) bundle:nil] forCellReuseIdentifier:@"ZJShaixuanCell"];
    
    UIButton* screenButton = [[UIButton alloc]initWithFrame:CGRectMake(3, 8, 40, 40)];
    [screenButton setImage:[UIImage imageNamed:@"hs_gb"]
                  forState:0];

    [screenButton addTarget:self
                     action:@selector(shaixuan)
           forControlEvents:UIControlEventTouchUpInside];

    self.view.backgroundColor = [UIColor clearColor];
    self.navigationController.view.backgroundColor = [UIColor clearColor];
    
     
     NSArray *subViews = [[[UIApplication sharedApplication].delegate window] subviews];
     
    for (UIView * view in subViews) {
        view.backgroundColor = [UIColor clearColor];

    }

    [self.view addSubview:screenButton];
    
}
-(void)shaixuan{
    if (self.sxArr) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"updata" object:@{@"arr":self.sxArr}];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}
//确定
- (IBAction)sureBtn:(id)sender {
    NSMutableArray * arr = [NSMutableArray new];
    
    if (house_layoutStr) {
        [arr addObject:house_layoutStr];
    }
    if (areaStr) {
        [arr addObject:areaStr];
    }
//    if (oriStr) {
//        [arr addObject:oriStr];
//    }

    if (arr.count < 1) {
        [HUD showMsg:@"请选择至少一个筛选条件"];
        self.sxArr = arr;
        return;
    }
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"updata" object:@{@"arr":arr}];
    [self dismissViewControllerAnimated:YES completion:nil];
}

//重置
- (IBAction)backBtn:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dataBack" object:@{@"backStr":self.backStr}];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section != 0) {
         return 49;
    }else return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 49)];
    view.backgroundColor = [UIColor whiteColor];
    
    if (section != 0) {
        return view;
    }else return  nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZJShaixuanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZJShaixuanCell"];
    cell.tag = indexPath.section;
    if (self.sxArr) {
         cell.sxArr = self.sxArr;
    }
    cell.delegate = self;
    switch (indexPath.section) {
        case 0:
            cell.modelArr = house_layoutArr;
            break;
        case 1:
            cell.modelArr = area_circleArr;
            break;
        case 2:
            cell.modelArr = orientationArr;
            break;
            
        default:
            break;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    [cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSArray * arr;
    
    switch (indexPath.section) {
        case 0:
            arr = house_layoutArr;
            break;
        case 1:
            arr = area_circleArr;
            break;
        case 2:
            arr = orientationArr;
            break;
        default:
            break;
    }
    
    CGFloat height = [self.tableview cellHeightForIndexPath:indexPath model:arr keyPath:@"modelArr" cellClass:[ZJShaixuanCell class] contentViewWidth:[Utils cellContentViewWith]];

    return height;;
    
}

-(void)clickHouse_layoutBtn:(NSString *)str{
    house_layoutStr = str;
    NSLog(@"选择了house_layoutStr:%@",house_layoutStr);
}

-(void)clickArea_circleBtn:(NSString *)str{
    areaStr = str;
    NSLog(@"选择了areaStr:%@",areaStr);
}

-(void)clickOrientationBtn:(NSString *)str{
    oriStr = str;
    NSLog(@"选择了oriStr:%@",oriStr);
}
@end
